﻿using PerformanceExamine.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PerformanceExamine.Models
{
    public class UserAppraisalBase
    {
        public int Id { get; set; }
        public string UserName { get; set; }
        public string Sex { get; set; }     
        public int BaseTypeId { get; set; }
        public string BaseType { get; set; }
        public int AppraisalBase { get; set; }
        public bool IsDel { get; set; }

        public static List<UserAppraisalBase> GetListJoinAppraisal()
        {
            List<UserAppraisalBase> userAppraisalBases = new List<UserAppraisalBase>(); 
            DataTable dt = SqlHelper.ExecuteTable("select  Users.Id,UserName,Sex,BaseTypeId,BaseType,AppraisalBase,Users.IsDel  from Users left join AppraisalBases on Users.BaseTypeId = AppraisalBases.Id");
            foreach (DataRow dr in dt.Rows)
            {
               userAppraisalBases.Add( ToModel(dr));
            }
            return userAppraisalBases;
        }
        private static UserAppraisalBase ToModel(DataRow dr)
        {
            UserAppraisalBase userAppraisalBase = new UserAppraisalBase();
            userAppraisalBase.Id = (int)dr["Id"];
            userAppraisalBase.UserName = dr["UserName"].ToString(); 
            userAppraisalBase.Sex = dr["Sex"].ToString();
            userAppraisalBase.BaseTypeId = (int)dr["BaseTypeId"];
            userAppraisalBase.BaseType = dr["BaseType"].ToString();
            userAppraisalBase.AppraisalBase = (int)dr["AppraisalBase"];
            userAppraisalBase.IsDel = (bool)dr["IsDel"];
            return userAppraisalBase; 
        }
    }
}
